package com.suep.system.controller;

import com.suep.system.config.BaseR;
import com.suep.system.domain.User;
import com.suep.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
//    邮箱验证码
//    ddzdsjwweqhvchbe
    @Autowired
    private IUserService userService;


    @GetMapping("/getUserInfo")
    public BaseR<User> getUserInfo(HttpServletRequest request){
        String username=(String)request.getAttribute("username");
        return new BaseR<>().ok("获取用户信息成功",userService.selectUserByUsername(username));

    }


    @GetMapping("/getAllUsers")
    public BaseR<List<User>> getAllUsers(){
        List<User> userList=userService.selectAllUsers();
        return new BaseR<>().ok("获取用户列表成功",userList);
    }

    @PostMapping("/updateUser")
    public BaseR<User> updateUser(@RequestBody User user){
        userService.updateUser(user);
        return new BaseR<>().ok("更新用户信息成功",user);
    }

}
